<?php
namespace app\controller;

use iflow\auth\Authorize\AuthAnnotation;
use iflow\facade\Cache;
use iflow\Response;
use iflow\Router\Controller;
use iflow\Router\implement\Request\GetMapping;

#[Controller('/')]
class index
{

    #[GetMapping('/api_template')]
    public function apiTemplate(): Response
    {
        return sendFile('api_template.html');
    }

    #[GetMapping('/store')]
    public function store()
    {
        // redis cache
        $store = Cache::store();
        $store -> set('123', ['id' => 1]);
        return message() -> success('success', $store -> get('123'));
    }

    #[GetMapping('/auth')]
    #[AuthAnnotation('auth', 'user')]
    public function auth(string $Authorization = 'null'): string {
        return 'role:'. $Authorization;
    }


    #[GetMapping('/send_mailer')]
    public function sendMailer(): array {
        $result = emails(['email@domain.com'], '2333', subject: 'Hi Email');
        return message() -> success(is_string($result) ? $result : 'status:ok');
    }
}
